package blue.mqtt4j.client.codec;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.parser.ParserConfig;

/**
 * @author Jin Zheng
 * @since 1.0 2020-10-29
 */
public class JsonDecoder implements Decoder
{
	private static Feature[] feature = new Feature[] {};

	static
	{
		ParserConfig.getGlobalInstance().setAutoTypeSupport(true);
	}

	public JsonDecoder()
	{
	}

	@Override
	public Object decode(byte[] bytes)
	{
		if (bytes == null || bytes.length == 0)
			return null;

		return JSON.parseObject(bytes, Object.class, feature);
	}
}
